package repositories

import (
	"context"
	"go.mongodb.org/mongo-driver/bson"
	"signature-service/global"
)

type UserPrivateKey struct {
	Id                 string  `bson:"_id,omitempty" json:"id"`
	UserId             string  `bson:"userId" json:"userId"`
	MainCoinType       int64   `bson:"mainCoinType" json:"mainCoinType"`       // udun的id
	FeeAddress         string  `bson:"feeAddress" json:"feeAddress"`           // 手续费地址（私钥）
	CollectAddress     string  `bson:"collectAddress" json:"collectAddress"`   // 归集地址
	WithdrawAddress    string  `bson:"withdrawAddress" json:"withdrawAddress"` // 提币地址（私钥）
	ChainName          string  `bson:"chainName" json:"chainName"`
	MinAmount          float64 `bson:"minAmount" json:"minAmount"` // 最小归集金额
	FeePrivateKey      string  `bson:"feePrivateKey" json:"feePrivateKey"`
	WithdrawPrivateKey string  `bson:"withdrawPrivateKey" json:"withdrawPrivateKey"`
	FeeBusinessId      string  `bson:"feeBusinessId" json:"feeBusinessId"`
	WithdrawBusinessId string  `bson:"withdrawBusinessId" json:"withdrawBusinessId"`
}

// GetUserPrivateKey 获取用户私钥
func (u *UserPrivateKey) GetUserPrivateKey(userId string, mainCoinType int64) error {
	client := global.DBEngine.Database(global.DBName).Collection("user_private_key")
	filter := bson.M{"userId": userId, "mainCoinType": mainCoinType}

	err := client.FindOne(context.TODO(), filter).Decode(&u)
	return err
}
